package com.tuozixuan.shell.command;

import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;

@ShellComponent
public class AvailabilityDemo {
	private boolean connected = false;

	@ShellMethod("Connect server")
	public void connect1() {
	    connected = true;
	}

	@ShellMethod("Download")
	@ShellMethodAvailability({"connectCheck"})
	public void download1() {
	    System.out.println("Downloaded.");
	}

	@ShellMethod("Upload")
	@ShellMethodAvailability({"connectCheck"})
	public void upload1() {
	    System.out.println("Uploaded.");
	}

	public Availability connectCheck() {
	    return connected ? Availability.available():Availability.unavailable("you are not connected");
	}
}
